<template>
  <div class="middle" v-if="bannerList.length > 0 && enBannerList.length > 0">
    <div class="title">{{ $t("common.gongyi") }}</div>
    <div class="mid">
      <div class="bigImgBox">
        <div class="item">
          <img
            :src="locale === 'zh-cn' ? bannerList[0].image : enBannerList[0].image"
            alt=""
          />

          <div class="detail">
            <el-button
              type="primary"
              class="lookBtn"
              @click="
                jumpTo(locale === 'zh-cn' ? bannerList[0].url : enBannerList[0].url)
              "
              >{{ $t("common.look") }}</el-button
            >
          </div>
        </div>
      </div>
      <div class="smallImgBox">
        <div class="item" v-for="(item, index) in list" :key="list">
          <img :src="item.image" alt="" />
          <div class="detail">
            <el-button
              type="primary"
              class="lookBtn"
              @click="jumpTo('/productDetail?id=' + item.id)"
              >{{ $t("common.look") }}</el-button
            >
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script setup>
import { reactive, ref, onMounted } from "vue";
import axios from "axios";
import { useRouter } from "vue-router";
const router = useRouter();
// 跳转页面
const jumpTo = (path) => {
  router.push(path);
};

const list = ref([]);
const getList = async () => {
  try {
    const res = await axios.get(`${apiUrl}/groom/list/4?page=1&limit=4`, {
      headers: {
        "Authori-zation": `Bearer ${getToken()}`,
      },
    });

    if (res.data.status === 200) {
      list.value = res.data.data.list;
    }
  } catch (e) {}
};

const bannerList = ref([]);
const getBanner = async () => {
  try {
    const res = await axios.get(`${apiUrl}/pc/get_good_pengbu_image`, {
      headers: {
        "Authori-zation": `Bearer ${getToken()}`,
      },
    });

    if (res.data.status === 200) {
      bannerList.value = res.data.data.list;
    }
  } catch (e) {}
};

const enBannerList = ref([]);
const getEnBanner = async () => {
  try {
    const res = await axios.get(`${apiUrl}/pc/get_en_good_pengbu_image`, {
      headers: {
        "Authori-zation": `Bearer ${getToken()}`,
      },
    });

    if (res.data.status === 200) {
      enBannerList.value = res.data.data.list;
    }
  } catch (e) {}
};

onMounted(() => {
  getList();
  getBanner();
  getEnBanner();
});
</script>

<style scoped lang="scss">
.middle {
  margin-top: 50px;

  .title {
    font-size: 32px;
    // font-weight: bold;
    text-align: center;
    margin-bottom: 30px;
  }

  .mid {
    display: flex;
    // background-color: #efefef;
  }

  .bigImgBox {
    margin-right: 3px;
    // margin: 5px;

    .item {
      width: 600px;
      height: 600px;
      position: relative;
      cursor: pointer;
      transition: 0.5s all;

      img {
        width: 100%;
        height: 100%;
      }
      &:hover {
        .detail {
          display: block;
        }
      }
    }
  }

  .smallImgBox {
    width: 750px;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    margin-left: 9px;
    .item {
      width: 297px;
      height: 295px;
      margin-bottom: 10px;
      background-color: #fff;
      position: relative;
      cursor: pointer;
      background-color: rgb(248, 248, 248);
      transition: 0.5s all;

      img {
        width: 100%;
        height: 100%;
      }

      &:hover {
        .detail {
          opacity: 1;
          visibility: visible;
        }
      }
    }
  }

  .detail {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    transition: 0.5s all;
    background-color: rgba($color: #fff, $alpha: 0.7);
    opacity: 0;
    visibility: hidden;

    .lookBtn {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: 150px;
      height: 41px;
      line-height: 41px;
      transition: 0.5s all;
    }
  }
}
</style>
